import router from './router'
import Vue from 'vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import App from './App.vue'
import {postKeyValueRequest} from "./utils/api";
import {postRequest} from "./utils/api";
import {getRequest} from "./utils/api";
import {deleteRequest} from "./utils/api";
import {putRequest} from "./utils/api";
import store from "./store"
import {initMenu} from "./utils/menu";
import echarts from 'echarts';


Vue.config.productionTip = false

Vue.prototype.postKeyValueRequest=postKeyValueRequest;
Vue.prototype.postRequest=postRequest;
Vue.prototype.deleteRequest=deleteRequest;
Vue.prototype.getRequest=getRequest;
Vue.prototype.putRequest=putRequest;
Vue.prototype.echarts = echarts;

Vue.use(ElementUI);

router.beforeEach((to,from,next)=>{
  if (to.path == '/'){
    next();
  }else {
    if(window.sessionStorage.getItem("user")){
      initMenu(router,store);
      next();
    }else {
      if (window.sessionStorage.getItem("user")) {
        initMenu(router, store);
        next();
      } else {
        next('/?redirect=' + to.path);
      }
    }
  }
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
